#ifndef CBORDERLABEL_H
#define CBORDERLABEL_H

#include <QWidget>
#include <QFrame>
#include <QLabel>
#include <QHBoxLayout>
class CBorderLabel : public QWidget
{
    Q_OBJECT
public:
    explicit CBorderLabel(bool bLeft = true,QWidget *parent = nullptr);


    void setGeometry(const QRect &);

    void setGeometry(int x,int y,int width,int height);
    //设置边距
    void setBorder(const QRect &);
    //top-right-bottom-left
    void setBorder(int top,int right,int bottom,int left);

    //设置label背景图
    //rc:背景图裁剪参数 top-right-bottom-left
    void setBorderImage(const QString &path,const QRect &rc = QRect(0,0,0,0));
    void setBorderImage(const QString &path,int top = 0,int right = 0,int bottom = 0,int left = 0);
    //设置文本对齐方式
    void setTextAlignment(Qt::Alignment);

    Qt::Alignment getTextAlignment();
    //设置文本
    void setText(const QString&);
    //设置文字大小
    void setFontSize(int size);
    //设置文字颜色
    void setFontColor(QString color);
    //设置文本内间距
    void setMargins(int left,int top,int right,int bottm);
private:
    void updateLabelBorderUI();
signals:
    void clicked();

private:
    QFrame* _bgiFrame = nullptr;
    QFrame* _textFrame = nullptr;

    QString _borderBGI = "";
    QRect _borderBGIClipRect = QRect();
    QRect _borderRect = QRect();

    QString _fontColor = QString("#000000");
    int _fontSize = 10;

    bool _bLeft = true;
    QLabel* _label;
    QHBoxLayout* _framelayout;
    QString _text;

    bool m_bIsPressed = false;
    bool m_bClickable = true;
};

//示例
//CBorderLabel* rightLb = new CBorderLabel(false,this);
//rightLb->setGeometry(200,100,300,17);
//rightLb->setBorder(9, 21, 6, 8);
//rightLb->setBorderImage(":/skin/right_winsteak.png",QRect(9,21,6,8));
//rightLb->setTextAlignment(Qt::AlignBottom|Qt::AlignHCenter);
//rightLb->setText("a x9999");

//QFrame *tmpFrame = new QFrame(this);
//tmpFrame->setGeometry(500,100,30,30);
//tmpFrame->setStyleSheet("background-color:blue;");

//CBorderLabel* leftLb = new CBorderLabel(true,this);
//leftLb->setGeometry(200,300,50,17);
//leftLb->setTextAlignment(Qt::AlignBottom|Qt::AlignHCenter);
//leftLb->setBorder(9, 8, 6, 21);
//leftLb->setBorderImage(":/skin/left_winsteak.png",QRect(9,8,6,21));
//leftLb->setFontColor("#00FF00");
//leftLb->setText("x 19992");

#endif // CBORDERLABEL_H
